package com.xiaoniu.lib_keleim

import android.content.Context
import com.xiaoniu.lib_keleim.db.ConversationListCallBack
import com.xiaoniu.lib_keleim.db.MessageCountCallBack
import com.xiaoniu.lib_keleim.db.MessageListCallBack
import com.xiaoniu.lib_keleim.pojo.dos.UserEntity
import com.xiaoniu.lib_keleim.pojo.vos.BaseMessage
import com.xiaoniu.lib_keleim.spi.*
import com.xiaoniu.lib_keleim.utils.*

class IMClient{

    private val mDispatcher = Dispatcher()

    companion object{
        private val mIMClient = IMClient();
        @JvmStatic
        fun getManager() :IMClient{
            return mIMClient
        }
    }
    fun connect(context: Context,userInfo:UserEntity?) {
        mDispatcher.connect(context,userInfo)
    }

    fun registerMsgType(msgType: HashMap<Int,Class<*>>) {
        mDispatcher.registerMsgType(msgType)
    }

    fun joinRoom(roomId: String) {
        mDispatcher.joinRoom(roomId)
    }

    fun quitRoom(roomId: String) {
        mDispatcher.quitRoom(roomId)
    }

    fun getConversations(schemes:Schemes,conversationType:ConversationType, targetId:String, callBack: ConversationListCallBack) {
        mDispatcher.getConversations(schemes,conversationType,targetId,callBack)
    }

    fun getMessages(schemes:Schemes, conversationType:ConversationType, targetId:String, channelId:String, option: HistoryMessageOption, callBack: MessageListCallBack) {
        mDispatcher.getMessages(schemes,conversationType,targetId,channelId,option,callBack)
    }

    fun getUnreadCount(schemes:Schemes,conversationType:ConversationType, targetId:String, channelId:String, callBack: MessageCountCallBack) {
        mDispatcher.getUnreadCount(schemes,conversationType,targetId,channelId,callBack)
    }

    fun sendMessage(message: BaseMessage) {
        mDispatcher.sendMessage(message)
    }

    fun insertMessage(message: BaseMessage) {
        mDispatcher.sendMessage(message)
    }

    fun addNetworkModule(networkModuleFactory: INetworkModuleFactory): IMClient {
        mDispatcher.addNetworkModule(networkModuleFactory)
        return this
    }

    fun addConverterFactory(converterFactory: IConverterFactory): IMClient {
        mDispatcher.addConverterFactory(converterFactory)
        return this
    }

    fun addInterceptor(interceptor: Interceptor): IMClient {
        mDispatcher.addInterceptor(interceptor)
        return this
    }

    fun retryOnConnectionFailure(retryOnConnectionFailure: Int): IMClient {
        mDispatcher.retryOnConnectionFailure(retryOnConnectionFailure)
        return this
    }

    fun addOnReceiveMessageListener(listener: ReceiveMessageListener): IMClient {
        mDispatcher.addOnReceiveMessageListener(listener)
        return this
    }
}